package cn.kongwg.jvmse;

import java.util.concurrent.TimeUnit;

/**
 * @author kongwg
 * @create 2021-05-13 22:20
 */

class Mynumber{
    volatile int number = 10;
    public void addNum(){
        this.number = 1024;
    }
}

public class JvmDemo2 {
    public static void main(String[] args) {
        Mynumber mynumber = new Mynumber();

        new Thread(() -> {
            System.out.println("********come in");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mynumber.addNum();
            System.out.println(Thread.currentThread().getName() + "\t update value");
        }, "a").start();
        while (mynumber.number == 10) {
            System.out.println("k");
        }
        System.out.println("ok-------------");
    }
}
